'''
Copyright 2010 Indra Bagus <indra.bagus@gmail.com> 
    
Licensed under the Apache License, Version 2.0 (the "License"); 
you may not use this file except in compliance with the License. 
You may obtain a copy of the License at 

    http://www.apache.org/licenses/LICENSE-2.0 
    
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. 
'''
from Type import WmxStringValue



class ManagementMessage(object):
    def __init__(self):
        self._cid   = 0
        self._type  = 0
        self._tlv_list = []

    
    @property
    def CID(self):
        return self._cid

    
    @CID.setter
    def CID(self,value):
        self._cid = value
        


class ULMap(ManagementMessage):
    '''
    ULMAP with no Information Element
    @author: Indra Bagus
    @contact: indra.bagus@gmail.com
    '''
    def __init__(self):
        super(ULMap,self).__init__()
        self._fdd_part_flag     = 0
        self.reserved           = 0
        self._ucd_count         = 0
        self._alloc_start_time  = 0
        self._no_ofdma_symbols  = 0
        
    
    @property    
    def fdd_part_flag(self):
        return self._fdd_part_flag
    
    
    @fdd_part_flag.setter
    def fdd_part_flag(self,val):
        self._fdd_part_flag = val
        
    
    @property
    def ucd_count(self):
        return self._ucd_count
    
    
    @ucd_count.setter
    def ucd_count(self,val):
        assert(isinstance(val,int) or isinstance(val,long))
        self._ucd_count = val
        
        
    @property
    def alloc_start_time(self):
        return self._alloc_start_time
    
    
    @alloc_start_time.setter
    def alloc_start_time(self,val):
        assert(isinstance(val, int) or isinstance(val,long))
        self._alloc_start_time = val
        
        
    
    @property 
    def no_ofdma_symbols(self):
        return self._no_ofdma_symbols
    
    
    @no_ofdma_symbols.setter
    def no_ofdma_symbols(self,val):
        assert(isinstance(val, int) or isinstance(val,long))
        self._no_ofdma_symbols = val
    


class DLMap(ManagementMessage):
    def __init__(self):
        super(DLMap,self).__init__()
        self.frame_duration_code = int()
        self.frame_number = int()
        self.dcd_count = int()
        self.bsid = WmxStringValue()# int()
        self.num_ofdma_symbols = int()



class UCD(ManagementMessage):
    '''
    Object UCD ini hanya berisi parameter 'header' saja, sedangkan paramater parameter
    lain seperti Uplink Burst Profile dan Uplink Channel Param akan diperoleh
    dengan cara mekanisme UCDHandler 
    '''
    def __init__(self):
        super(UCD,self).__init__()
        self.configuration_change_count = 0
        self.ranging_back_off_start     = 0x00
        self.ranging_back_off_end       = 0x00
        self.request_back_off_start     = 0x00
        self.request_back_off_end       = 0x00       
        
        
    class ULBurstProfile(object):
        '''
        Nested UL Burst profile object
        '''
        def __init__(self,uiuc):
            self.type       = int()
            self.length     = int()
            self.reserved   = int()
            self.uiuc       = uiuc
            self.tlv_list   = [] 
            
        def __repr__(self):
            return repr(self.tlv_list)
        
        

class DCD(ManagementMessage):
    def __init__(self):
        self.reserved = int()
        self.conf_change_count = int()
    
    
    class DLBustProfile(object):
        def __init__(self,diuc):
            self.type       = int()
            self.length     = int()
            self.reserved   = int()
            self.diuc       = diuc
            self.tlv_list   = []
